package com.nbicc.survey.service.impl;

import com.nbicc.parent.serivce.BaseService;
import com.nbicc.survey.mapper.MultipleChoiceTopicMapper;
import com.nbicc.survey.po.MultipleChoiceTopic;
import com.nbicc.survey.service.IMultipleChoiceTopicService;
import com.nbicc.utils.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service("MultipleChoiceTopicServiceImpl")
public class MultipleChoiceTopicServiceImpl extends BaseService implements IMultipleChoiceTopicService {

    @Autowired
    private MultipleChoiceTopicMapper multipleChoiceTopicMapper;

    @Override
    public MultipleChoiceTopic selectById(String id) {
        return multipleChoiceTopicMapper.selectById(id);
    }


    @Override
    public Integer insert(MultipleChoiceTopic multipleChoiceTopic) {
        multipleChoiceTopic.setId(ToolUtil.generateUUID32());
        multipleChoiceTopic.setCreateTime(new Date());
        return multipleChoiceTopicMapper.insert(multipleChoiceTopic);
    }

    @Transactional
    @Override
    public Integer batchInsert(List<MultipleChoiceTopic> multipleChoiceTopicList) {
        for (MultipleChoiceTopic multipleChoiceTopic : multipleChoiceTopicList) {
            insert(multipleChoiceTopic);
        }
        return 1;
    }

    @Override
    public Integer updateById(MultipleChoiceTopic multipleChoiceTopic) {
        return multipleChoiceTopicMapper.updateById(multipleChoiceTopic);
    }

    @Override
    public Integer deleteById(String id) {
        return multipleChoiceTopicMapper.deleteById(id);
    }

    @Override
    public List<MultipleChoiceTopic> selectListByQuestionnaireId(String questionnaireId) {
        return multipleChoiceTopicMapper.selectListByQuestionnaireId(questionnaireId);
    }

}
